<?php

namespace Driver\Controller;

use Think\Controller;

class IndexController extends BaseController {

    protected $m;

    public function _initialize(){

        parent::_initialize();

        if(!$this->userInfo['auth'])

            error_sys('当前用户认证尚未通过,如填写过资料请耐心等待',3);

    }

    /*司机首页*/

    public function index(){

        $m_order=M('order');

        $status=I('get.status','done');

        $type=I('get.type');//1是司机2是工人

        $page=I('get.page',0);

        $pageSize=I('get.pageSize',5);

        $tel= M('config')->where(['key'=>'Tel'])->getField('value');

        if($status=='done')
            $where['status']=['in',[4,5]];
        else
            $where['status']=['in',[0,1,2,3]];
        // if($type == 1){
        //     //是司机访问
        //     $where['driver_id']=$this->member_id;
        // }else{
        //     //是随车工人
        //     $car = M('car')->field(['car_id'])->where('FIND_IN_SET('.$this->member_id.',worker_id)')->select();
        //     $arr =[];//已绑定工人的车辆列表
        //     if(!empty($car)){
        //         foreach ($car as $kk => $vv) {
        //             array_push($arr,$vv['car_id']);//拼接成数组 方便IN查询
        //         }
        //     }
        //     $where['car_id']=array('in',$arr);
        //     // ll($arr);die;
        // }
        $where['driver_id']=$this->member_id;
        $list=$m_order->where($where)->page($page,$pageSize)->field('id,order_no,addtime,status,departure,arrival,booktime,product_info,tel,total_price,is_online')->select();
        // ll($list);
        // echo $m_order->getLastsql();die;
        if(!empty($list)){
            foreach ($list as $k=>$v){
                $list[$k]['product_info']=json_decode($v['product_info']);
                $list[$k]['tell'] = $tel;
            }
        }
        $count=$m_order->where($where)->count();
        success([
            'list'=>$list,
            'count'=>$count,
            'statistics'=>[
                $this->statistics()
            ]
        ]);

    }

}